package com.kingdee.pda.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.basecommon.utils.SpeakUtils;
import com.kingdee.pda.R;
import com.kingdee.pda.entity.ReplenishSkuBean;
import com.kingdee.pda.util.CommonUtil;

import java.util.List;

/**
 * @author：dlj
 * @data：2021/7/20:15:10
 * @des：
 */
public class ReplenishUpdateNumAdapter extends BaseQuickAdapter<ReplenishSkuBean.ActulBean, BaseViewHolder> {

    private Context context;

    public ReplenishUpdateNumAdapter(Context context, List<ReplenishSkuBean.ActulBean> beans) {
        super(R.layout.item_replenish_updatesnum, beans);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder viewHolder, ReplenishSkuBean.ActulBean item) {
        viewHolder.setText(R.id.tv_skuCode, item.getItemBarCode())
                .setText(R.id.tv_actulFormLocationCode, item.getActualFromLocationNumber());

        EditText et_actulQty = viewHolder.getView(R.id.et_actulQty);
        et_actulQty.setText(item.getActulQty() + "");
        et_actulQty.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    int qty = Integer.parseInt(et_actulQty.getText().toString());
                    if (qty <= 0) {
                        SpeakUtils.speakWithToast(context, "补货数量必须大于0！", false, false);
                    } else {
                        item.setActulQty(qty);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        CommonUtil.requestFocusAndNoClearText(et_actulQty);
    }
}
